package com.ecmap.hongyun.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.ecmap.hongyun.dao.IUserDAO;
import com.ecmap.hongyun.model.User;
import com.ecpark.commons.base.BaseDAOHibernate;

@Repository("userDAO")
public class UserDAOImpl extends BaseDAOHibernate implements IUserDAO {

	@Override
	protected Class<User> getModelClass() {
		return User.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public User findUserByUsername(String username) {
		List<User> users = null ;
		Session session = super.getSession();
		try{
			users = doQueryHQL(" from User u where u.username=?", session)
					.setString(0, username)
					.list();
			
		}catch(Exception e){
			
		}finally{
			releaseSession(session);
		}
		
		return users != null && users.size() > 0 ? users.get(0):null ;
	}

	@Override
	public User findUserById(Long id) {
		return (User)doFindObjectById(id);
	}

	@Override
	public void updateUser(User user) {
		doUpdateObject(user);
	}

}
